package org.sepheriel.airy2d.physic;

import org.sepheriel.airy2d.math.Vec2;

public class Rectangle {

	private Vec2 pos;
	private int width;
	private int height;
	
	public Rectangle(Vec2 pos, int width, int height) {
		this.setPos(pos);
		this.setWidth(width);
		this.setHeight(height);
	}
	
	public Rectangle(Rectangle other) {
		this.pos = new Vec2(other.getPos());
		this.width = other.width;
		this.height = other.height;
	}
	
	public boolean inside(Vec2 point) {
		//System.out.println(point);
		//System.out.println(pos);
		if((point.getX() >= pos.getX()
				&& point.getX() <= pos.getX()+this.getWidth())
				&& (point.getY() >= pos.getY() && point.getY() <= pos.getY()+this.getHeight())) {
			return true;
		} else {
			return false;
		}
	}
	
	public boolean overlap(Rectangle other) {
		if(			this.inside(other.getPos())
				||	this.inside(other.getTopRight())
				||	this.inside(other.getBottomLeft())
				||  this.inside(other.getEndPoint())
				||  other.inside(this.getPos())
				||	other.inside(this.getTopRight())
				||	other.inside(this.getBottomLeft())
				||  other.inside(this.getEndPoint()))
		{
			return true;
		} else {
			return false;
		}
	}
	
	public Vec2 getCenter() {
		return new Vec2(this.pos.getX()+this.getWidth()/2, this.pos.getY()+this.getHeight()/2);
	}

	public Vec2 getPos() {
		return pos;
	}
	
	public Vec2 getTopRight() {
		return new Vec2(this.pos.getX()+this.getWidth(), this.pos.getY());
	}
	
	public Vec2 getBottomLeft() {
		return new Vec2(this.pos.getX(), this.pos.getY()+this.getHeight());
	}
	
	public Vec2 getEndPoint() {
		return new Vec2(this.pos.getX()+this.width, this.pos.getY()+this.height);
	}
	
	public void setPos(Vec2 pos) {
		this.pos = new Vec2(pos.getX(), pos.getY());
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getX() {
		return this.pos.getX();
	}

	public void setX(int f) {
		this.pos.setX(f);
	}

	public int getY() {
		return this.pos.getY();
	}

	public void setY(int f) {
		this.pos.setY(f);
	}
	
	public String toString() {
		return this.getPos().toString()+"/"+this.getEndPoint().toString();
	}
	
}
